package com.springboot.service.impl;

import com.springboot.aop.DB;
import com.springboot.mapper.UserInfoMapper;
import com.springboot.mapper.UserMapper;
import com.springboot.pojo.User;
import com.springboot.pojo.UserInfo;
import com.springboot.service.UserInfoService;
import com.springboot.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
@DB("aliDB")
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Resource
    private UserInfoService userInfoService;

    @Override
    public List<User> list() {
        List<User> users = userMapper.list();
        List<User> userInfo = getUserInfo();
        users.addAll(userInfo);
        return users;
    }

    public List<User> getUserInfo() {
        List<UserInfo> list =  userInfoService.list();
        return list.stream().map(em -> {
            User user = new User();
            BeanUtils.copyProperties(em, user);
            return user;
        }).collect(Collectors.toList());
    }

}
